[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-09-06
-->
[@JGP.head "数据"/]
[@JGP.body]
    <jgp-div _id="wrap" _row="['30','0','*']" _runit="px">
        <jgp-query slot="1-1" _action="/form/formApiController/queryFormValue" _cols="24" _auto="false" _is_cus_form="true">
            <jgp-text _label="选择表单" _id="form-name" _submit="false" _operator="LIKE" _name="name" _hastool="true" _readonly="true">
                <jgp-btn slot="tool" _size="tiny" _icon="bars" _color="plain" _margin="3px" _fn="openSelectForm"></jgp-btn>
            </jgp-text>
            <jgp-btn _margin="5" _fn="addFormValue">{{data.addBtnText}}</jgp-btn>
            <jgp-btn _margin="5" _fn="query">查询</jgp-btn>
        </jgp-query>
        <jgp-query slot="2-1" _id="value-query" _target="value-grid" _label_width="80px" _cols="24" _auto="false" _over_render="doOverRenderFn">
            [#--<jgp-text _name="testModel.bridgeName" _label="桥梁名称"></jgp-text>--]
            <jgp-hidden _id="form-code" _name="formCode"></jgp-hidden>
        </jgp-query>
        <jgp-grid slot="3-1" _id="value-grid" _record_tools="[{'icon':'edit','tip':'修改','fn':'editFormValue'},
                  {'icon':'trash-o','tip':'删除','fn':'removeFormValue'}]"></jgp-grid>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        var currentForm;
        var filters;
        JGP.$onload(function () {
            JGP.$putData('addBtnText','添加内容');
            JGP.$putData('filters',filters);
        })

        function doOverRenderFn(){
            var queryForm = JGP.query('value-query');
            if(queryForm.getHeight()>1){
                var wrap = JGP.div('wrap');
                wrap.attr('row',"['45','"+queryForm.getHeight()+"','*']");
                query();
            }
        }

        function openSelectForm() {
            var dialog = {
                'title': '选择查询项',
                'width': '500px',
                'height': '470px',
                'url': '/form/formController/selectForm',
                'callback': function (result) {
                    if(result){
                        currentForm = result;
                        JGP.$putData('addBtnText','添加'+result.name);
                        JGP.text('form-name').val(result.name);
                        var queryForm = JGP.query('value-query');
                        queryForm.attr('_render_form_code',result.code);
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function addFormValue() {
            if(!currentForm){
                JGP.$warn('请选择表单')
            }else {
                var dialog = {
                    'title': '添加'+currentForm.name,
                    'width': '700px',
                    'height': '600px',
                    'url': '/form/formController/addFormValue?formId='+currentForm.id,
                    'callback': function (result) {
                        if(result){
                            query();
                        }
                    }
                };
                JGP.$dialog(dialog);
            }
        }

        function editFormValue(args) {
            if(!currentForm){
                JGP.$warn('请选择表单')
            }else {
                var dialog = {
                    'title': '编辑'+currentForm.name+'(ID:'+args.back.record.virtualFormResponseData.bizId+')',
                    'width': '700px',
                    'height': '600px',
                    'url': '/form/formController/editFormValue/'+currentForm.id+'/'+args.back.record.virtualFormResponseData.bizId,
                    'callback': function (result) {
                        if(result){
                            query();
                        }
                    }
                };
                JGP.$dialog(dialog);
            }
        }

        function query() {
            JGP.query('value-query').search();
        }

        function removeFormValue(args) {
            JGP.$confirm('确认删除?',function () {
                JGP.$post('/form/formApiController/removeFormValue/'+args.back.record.bizId,{},function (result) {
                    if(result.flag){
                        query();
                    }
                })
            })
        }

    </script>
[/@JGP.foot]